#include "loadanimation.h"
#include <QHBoxLayout>

#include "highlight-effect.h"

const int ICON_MAX_NUM = 8;

LoadAnimation::LoadAnimation(QWidget *parent) : QWidget(parent)
{
    m_loadLab = new QLabel(this);
    m_timer = new QTimer(this);

    QHBoxLayout *hLayout = new QHBoxLayout;
    hLayout->addStretch();
    hLayout->addWidget(m_loadLab);
    hLayout->addStretch();

    QVBoxLayout *vLayout = new QVBoxLayout;
    vLayout->addStretch();
    vLayout->addLayout(hLayout);
    vLayout->addStretch();

    setLayout(vLayout);

    m_loadLab->setPixmap(QPixmap(":/loadicon/" + QString::number(m_count) + ".png"));

    connect(m_timer, &QTimer::timeout, this, &LoadAnimation::timeout);
    m_timer->start(100);
}

void LoadAnimation::setHighLight()
{
    m_loadLab->setProperty("useIconHighlightEffect", 0x2);
}

void LoadAnimation::timeout()
{
    QString qpmQss = ":/loadicon/";
    qpmQss.append(QString::number(m_count));
    qpmQss.append(".png");
    m_loadLab->setPixmap(QPixmap(qpmQss));
    m_count++;
    if (m_count == ICON_MAX_NUM) {
        m_count = 1;
    }
}
